package com.example.amazing_wangjj.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.amazing_wangjj.mapper.AppointmentMapper;
import com.example.amazing_wangjj.pojo.Appointment;
import com.example.amazing_wangjj.service.AppointmentService;
import org.springframework.stereotype.Service;

@Service
//mybatis-plus的service实现类，继承ServiceImpl接口，泛型传入mapper类和POJO持久类,
public class AppointmentServiceImpl extends ServiceImpl<AppointmentMapper, Appointment>
        implements AppointmentService {

    /**
     * 查询订单是否存在
     * @param appointment
     * @return
     */
    @Override
    public Appointment getOne(Appointment appointment) {
        //lambda表达式,查询条件,查询条件为"传入的appointment对象的username,idCard,department,date,time等属性是否哟完全相同的appointment对象，若有，则证明订单重复
        LambdaQueryWrapper<Appointment> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(Appointment::getUsername, appointment.getUsername());
        queryWrapper.eq(Appointment::getIdCard, appointment.getIdCard());
        queryWrapper.eq(Appointment::getDepartment, appointment.getDepartment());
        queryWrapper.eq(Appointment::getDate, appointment.getDate());
        queryWrapper.eq(Appointment::getTime, appointment.getTime());
        Appointment appointmentDB = baseMapper.selectOne(queryWrapper);
        return appointmentDB;
    }
}
